package firstStage.part9;

import java.util.Scanner;

/**
 * @ClassName: [StringTest3]
 * @Description: 拼接字符串、字符串反转
 * @Author: [黄劲松]
 * @CreateDate: [2021-02-07]
 * @Version: [v1.0]
 */
/*
String类中的方法
方法名                                   说明
public boolean equals(Object anObject)  比较字符串的内容，严格区分大小写(用户名和密码)
public char charAt(int index)           返回指定索引处的char值
public int length()                     返回此字符串的长度
*/
public class StringTest3 {
    public static void main(String[] args) {
        //字符串拼接
        int[] arr = {1, 2, 3};
        String s = arrayToString(arr);
        System.out.println("s:" + s);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入第一个字符串：");
        String line1 = scanner.nextLine();
        System.out.println("请输入第二个字符串：");
        String line2 = scanner.nextLine();
        String Line = arrayToString(line1 + line2);
        System.out.println("Line：" + Line);
        //字符串反转
        System.out.println("请输入需要字符反转的字符串：");
        String line3 = scanner.nextLine();
        String Line1 = reverseString(line3);
        System.out.println("Line1：" + Line1);

    }

    public static String arrayToString(int[] arr) {
        String s = "";
        s += "[";
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                s += arr[i];
            } else {
                s += arr[i];
                s += ",";
            }
        }
        s += "]";
        return s;
    }

    public static String arrayToString(String arr) {
        String s = "";
        s += "[";
        for (int i = 0; i < arr.length(); i++) {
            if (i == arr.length() - 1) {
                s += arr.charAt(i);
            } else {
                s += arr.charAt(i);
                s += ",";
            }
        }
        s += "]";
        return s;
    }

    public static String reverseString(String s) {
        String ss = "";
        for (int i = s.length() - 1; i >= 0; i--) {
            ss += s.charAt(i);
        }
        return ss;
    }
}
